package leetcode_acm.string;

import org.junit.Test;

/**
 * 功能描述
 *
 * @author: 张庭杰
 * @date: 2023年03月22日 9:52
 */
public class ReplaceSpace  {
    public String replaceSpace(String ss) {
        char[] s = ss.toCharArray();
        int length = s.length;
        int count = 0;
        for (char c : s) {
            if (c == ' ') {
                count++;
            }
        }
        char[] str = new char[s.length+count*2];
        for(int i = s.length-1,j = str.length-1;i>=0&&j>=0;i--,j--){
            if(s[i] == ' '){
                str[j] = '0';
                str[j-1] = '2';
                str[j-2] = '%';
                j -= 2;
            }else{
                str[j] = s[i];
            }
        }
        return new String(str);
    }

    @Test
    public void test(){
        System.out.println(replaceSpace("We are happy."));
    }
}
